<?php
class CommentController extends Zend_Controller_Action{
	function init(){
		if ($_SESSION['user'] == "") {
			echo "<script>window.location='../user/login';</script>"; exit;
		}
		$this->registry = Zend_Registry::getInstance();
		$this->view = $this->registry['view'];
		$this->view->baseUrl = $this->_request->getBaseUrl();
		$this->view->template = "comment";
	}

	public function addAction(){
		$filter = new Zend_Filter_StripTags();
		$comment = new Comment();
		$operation = new Operation();
		if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
			$content=$filter->filter(($this->_request->getPost('content')));
			$recommend=$filter->filter(($this->_request->getPost('recommend')));
			$score=$filter->filter(($this->_request->getPost('score')));
			$cid=$filter->filter(($this->_request->getPost('cid')));
			$category=$filter->filter(($this->_request->getPost('category')));
			$template=$filter->filter(($this->_request->getPost('template')));
			$uid=$_SESSION['user']['user_id'];;
			$create_time = time();
			$data = array(
				'content'=>$content,
				'recommend'=>$recommend,
				'level'=>$score,
				'user_id'=>$uid,
				'category'=>$category,
				'cid'=>$cid,
				'create_time'=>$create_time
			);
			$id = $comment->insert($data);
			if ($id) {
				$time = time();
				$data = array(
					'op_name'=>'add',
					'model_name'=>'comment',
					'user_id'=>$_SESSION['user']['user_id'],
					'user_name'=>$_SESSION['user']['user_name'],
					'name'=>'增加评论',
					'create_time'=>$time
				);
				$query = $operation->insert($data);
				echo "<script>window.location='".$this->_request->getBaseUrl()."/".$template."/detail?".$template."_id=$cid';</script>";
			} else {
				
			}
		}
	}
}
?>
